/**
 * @project readnote
 * @Title ExpostulationAction.java
 * @deprecated 前台-励志谏言管理
 * @author huxh
 * @date 2012-2-12
 **/
package com.readnote.center;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.cr.backbone.action.AppBaseActionSupport;
import com.readnote.expostulation.model.Expostulation;
import com.readnote.expostulation.service.ExpostulationService;
import com.readnote.user.model.User;

public class ExpostulationAction extends AppBaseActionSupport{
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -7372949060374992497L;
	private Expostulation expostulation;
	private Collection<Expostulation> expostulations;
	private ExpostulationService expostulationService;
	
	public String index(){
		//1、当前登录者
		User user=getLoginInfo().getUser();
		Long userId=user ==null || user.isNullRow()?null:user.getId();
		getQuery().addQuery("eq_createUser.id_l", userId);
		
		getQuery().addOrderDesc("id");
		page = expostulationService.getPage(getQuery(),page);
		return INDEX;
	}
	
	public String input(){
		if(expostulation!=null && !expostulation.isNullRow())
			expostulation = expostulationService.get(expostulation.getId());
		return INPUT;
	}
	
	public String save(){
		User user = getLoginInfo().getUser();
		Date applyDate=new Date();
		expostulationService.saveExpostulation(expostulation,user,applyDate);
		return SUCCESS;
	}
	
	public String delete(){
		expostulationService.delete(expostulation);
		return SUCCESS;
	}

	public String view(){
		expostulation=expostulationService.get(expostulation.getId());
		return VIEW;
	}

	
	
	
	
	public Expostulation getExpostulation() {
		return expostulation;
	}

	public void setExpostulation(Expostulation expostulation) {
		this.expostulation = expostulation;
	}

	public ExpostulationService getExpostulationService() {
		return expostulationService;
	}

	public void setExpostulationService(ExpostulationService expostulationService) {
		this.expostulationService = expostulationService;
	}

	public Collection<Expostulation> getExpostulations() {
		expostulations =expostulationService.getList();
		try {
			User user=getLoginInfo().getUser();
			expostulations = expostulationService.getListExpostulationByUserOrderCreateDateDesc(user);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		//(expostulations);
		return expostulations;
	}

	public void setExpostulations(List<Expostulation> expostulations) {
		this.expostulations = expostulations;
	}
	
	private Expostulation one;
	
	
	public Expostulation getOne() {
		User user=getLoginInfo().getUser();
		one= expostulationService.getExpostulationTopOneByCreateDateDesc(user);
		return one;
	}

	
}
